home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mainevt.c < prev    next >
C/C++ Source or Header  |  2000-04-20  |  4KB  |  147 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11. #include "vidhrdw/konamiic.h"
  12.  
  13.  
  14. static int layer_colorbase[3],sprite_colorbase;
  15.  
  16.  
  17.  
  18. /***************************************************************************
  19.  
  20.   Callbacks for the K052109
  21.  
  22. ***************************************************************************/
  23.  
  24. static void mainevt_tile_callback(int layer,int bank,int *code,int *color)
  25. {
  26.     tile_info.flags = (*color & 0x02) ? TILE_FLIPX : 0;
  27.  
  28.     /* priority relative to HALF priority sprites */
  29.     if (layer == 2) tile_info.priority = (*color & 0x20) >> 5;
  30.     else tile_info.priority = 0;
  31.  
  32.     *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
  33.     *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
  34. }
  35.  
  36. static void dv_tile_callback(int layer,int bank,int *code,int *color)
  37. {
  38.     /* (color & 0x02) is flip y handled internally by the 052109 */
  39.     *code |= ((*color & 0x01) << 8) | ((*color & 0x3c) << 7);
  40.     *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
  41. }
  42.  
  43.  
  44. /***************************************************************************
  45.  
  46.   Callbacks for the K051960
  47.  
  48. ***************************************************************************/
  49.  
  50. static void mainevt_sprite_callback(int *code,int *color,int *priority_mask)
  51. {
  52.     /* bit 5 = priority over layer B (has precedence) */
  53.     /* bit 6 = HALF priority over layer B (used for crowd when you get out of the ring) */
  54.     if (*color & 0x20)        *priority_mask = 0xff00;
  55.     else if (*color & 0x40)    *priority_mask = 0xff00|0xf0f0;
  56.     else                    *priority_mask = 0xff00|0xf0f0|0xcccc;
  57.     /* bit 7 is shadow, not used */
  58.  
  59.     *color = sprite_colorbase + (*color & 0x03);
  60. }
  61.  
  62. static void dv_sprite_callback(int *code,int *color,int *priority)
  63. {
  64.     /* TODO: the priority/shadow handling (bits 5-7) seems to be quite complex (see PROM) */
  65.     *color = sprite_colorbase + (*color & 0x07);
  66. }
  67.  
  68.  
  69. /*****************************************************************************/
  70.  
  71. int mainevt_vh_start(void)
  72. {
  73.     layer_colorbase[0] = 0;
  74.     layer_colorbase[1] = 8;
  75.     layer_colorbase[2] = 4;
  76.     sprite_colorbase = 12;
  77.  
  78.     if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,mainevt_tile_callback))
  79.         return 1;
  80.     if (K051960_vh_start(REGION_GFX2,NORMAL_PLANE_ORDER,mainevt_sprite_callback))
  81.     {
  82.         K052109_vh_stop();
  83.         return 1;
  84.     }
  85.  
  86.     return 0;
  87. }
  88.  
  89. int dv_vh_start(void)
  90. {
  91.     layer_colorbase[0] = 0;
  92.     layer_colorbase[1] = 0;
  93.     layer_colorbase[2] = 4;
  94.     sprite_colorbase = 8;
  95.  
  96.     if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,dv_tile_callback))
  97.         return 1;
  98.     if (K051960_vh_start(REGION_GFX2,NORMAL_PLANE_ORDER,dv_sprite_callback))
  99.     {
  100.         K052109_vh_stop();
  101.         return 1;
  102.     }
  103.  
  104.     return 0;
  105. }
  106.  
  107. void mainevt_vh_stop(void)
  108. {
  109.     K052109_vh_stop();
  110.     K051960_vh_stop();
  111. }
  112.  
  113. /*****************************************************************************/
  114.  
  115. void mainevt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  116. {
  117.     K052109_tilemap_update();
  118.  
  119.     if (palette_recalc())
  120.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  121.  
  122.     tilemap_render(ALL_TILEMAPS);
  123.  
  124.     fillbitmap(priority_bitmap,0,NULL);
  125.     K052109_tilemap_draw(bitmap,1,TILEMAP_IGNORE_TRANSPARENCY|(1<<16));
  126.     K052109_tilemap_draw(bitmap,2,1|(2<<16));    /* low priority part of layer */
  127.     K052109_tilemap_draw(bitmap,2,0|(4<<16));    /* high priority part of layer */
  128.     K052109_tilemap_draw(bitmap,0,8<<16);
  129.  
  130.     K051960_sprites_draw(bitmap,-1,-1);
  131. }
  132.  
  133. void dv_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  134. {
  135.     K052109_tilemap_update();
  136.  
  137.     if (palette_recalc())
  138.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  139.  
  140.     tilemap_render(ALL_TILEMAPS);
  141.  
  142.     K052109_tilemap_draw(bitmap,1,TILEMAP_IGNORE_TRANSPARENCY);
  143.     K052109_tilemap_draw(bitmap,2,0);
  144.     K051960_sprites_draw(bitmap,0,0);
  145.     K052109_tilemap_draw(bitmap,0,0);
  146. }
  147.